package com.starbaba.apiActivity.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.base.common.database.BaseDao;
import com.base.common.exception.AppException;
import com.base.common.util.StringUtils;
import com.starbaba.apiActivity.service.ApiModelBasisConfService;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.model.dictionary.Constant;
import com.tuanzi.server.loan_base.model.db.apiModel.ApiModelItemBasis;

@Component
public class ApiModelBasisConfServiceImpl implements ApiModelBasisConfService{
	
	@SuppressWarnings("deprecation")
    private static BaseDao dao = new BaseDao(Constant.POOL_LIFE);
	
	public List<ApiModelItemBasis> getDateList(int iDisplayStart, int iDisplayLength, PageResponse pageResponse, Map<String, Object> paramsMap){
		String itemId = (String) paramsMap.get("itemId");
		String itemName = (String) paramsMap.get("itemName");

		String sql = "SELECT b.id ,b.type_id ,b.project_id,b.title ,b.data_key ,b.create_time FROM loan_api_model_itembasis b,loan_api_model_type t,loan_api_model_project p WHERE b.type_id = t.id and b.project_id = p.id ";
		
		String selectSql = "";
		if (!StringUtils.isEmpty(itemId)) {
            selectSql += " AND b.id = " + itemId ;
        }
		if (!StringUtils.isEmpty(itemName)) {
			selectSql += " AND b.title LIKE '%" +itemName + "%'";
		}

		sql += selectSql;
		sql += " order by b.create_time desc limit " + iDisplayStart + " , " + iDisplayLength;

		String countSql = "select count(1) from loan_api_model_itembasis b where 1=1 " + selectSql;
		
		List<ApiModelItemBasis> list = null;
		try {
			int count = dao.getInt(countSql);
			list = dao.list(sql, ApiModelItemBasis.class, new Object[] {});
			pageResponse.setITotalRecords(count);
			pageResponse.setITotalDisplayRecords(count);
		} catch (AppException e) {
			e.printStackTrace();
		}
		return list;
	}

}




